/**
 * Basic frontend tests
 */

import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';

// Simple test to verify testing setup
describe('Basic Frontend Tests', () => {
  test('renders without crashing', () => {
    const div = document.createElement('div');
    document.body.appendChild(div);
    expect(div).toBeInTheDocument();
    document.body.removeChild(div);
  });

  test('can render text', () => {
    render(<div>Test Text</div>);
    expect(screen.getByText('Test Text')).toBeInTheDocument();
  });

  test('localStorage mock works', () => {
    const mockSetItem = jest.fn();
    const mockGetItem = jest.fn();

    Object.defineProperty(window, 'localStorage', {
      value: {
        setItem: mockSetItem,
        getItem: mockGetItem,
        removeItem: jest.fn(),
        clear: jest.fn(),
      },
      writable: true,
    });

    localStorage.setItem('test', 'value');
    expect(mockSetItem).toHaveBeenCalledWith('test', 'value');
  });

  test('can mock fetch', () => {
    global.fetch = jest.fn(() =>
      Promise.resolve({
        json: () => Promise.resolve({ success: true }),
      })
    ) as jest.Mock;

    expect(fetch).toBeDefined();
  });

  test('can handle async operations', async () => {
    const asyncFunction = async () => {
      return Promise.resolve('test result');
    };

    const result = await asyncFunction();
    expect(result).toBe('test result');
  });
});